1   /************************************************************
2   *                     Copyright                            *
3   * Portions of this software are Copyright (c) 1993 - 2002, *
4   * Chad Z. Hower (Kudzu) and the Indy Pit Crew              *
5   *  - http://www.nevrona.com/Indy/                          *
6   ************************************************************/
7   package org.indy;
8   
9   import org.indy.io.IndyIOException;
10  import org.indy.io.NotConnectedException;
11  import org.indy.io.PeerDisconnectedException;
12  
13  
14  /***
15   *  Description of the Class
16   *
17   *@author    owen
18   */
19  public class PeerThread extends IndyThread {
20    private TCPServerConnection connection;
21  
22    /***
23   *  Constructor for the IdPeerThread object
24   */
25    public PeerThread() {
26    }
27  
28    /***
29   *  Sets the connection attribute of the IdPeerThread object
30   *
31   *@param  connection  The new connection value
32   */
33    public void setConnection(TCPServerConnection connection) {
34      this.connection = connection;
35    }
36  
37    /***
38   *  Gets the connection attribute of the IdPeerThread object
39   *
40   *@return    The connection value
41   */
42    public TCPServerConnection getConnection() {
43      return connection;
44    }
45  
46    /***
47   *  Description of the Method
48   */
49    protected synchronized void beforeRun() throws InterruptedException {
50      if (connection.getIOHandler() == null) {
51        /*** @todo Sort exception */
52  
53        //this should be thrown or sent to server.doException?
54        //throw new IdTCPServerError("");
55      }
56  
57  
58      /***
59   *@todo    intercept stuff
60   */
61      connection.getServer().doConnect(this);
62  
63      if (!connection.isConnected()) {
64        stop();
65      }
66    }
67  
68    /***
69   *  Description of the Method
70   */
71    protected synchronized void afterRun() throws InterruptedException {
72      connection.getServer().doDisconnect(this);
73    }
74  
75    /***
76     * DOCUMENT ME!
77     *
78     * @throws InterruptedException DOCUMENT ME!
79     */
80    protected synchronized void cleanup() throws InterruptedException {
81      connection = null;
82      connection.getServer().getThreadManager().releaseThread(this);
83    }
84  
85    /***
86     * DOCUMENT ME!
87     */
88    public void terminate() {
89      if (connection != null) {
90        connection.disconnectSocket();
91      }
92  
93      super.terminate();
94    }
95  
96    /***
97   *  Main processing method for the IdPeerThread object
98   */
99    public void run() {
100     try {
101       try {
102         connection.getServer().doExecute(this);
103       }
104        catch (PeerDisconnectedException ccge) {
105         connection.getServer().doException(this, ccge);
106       }
107        catch (NotConnectedException nce) {
108         connection.getServer().doException(this, nce);
109       }
110        catch (IndyIOException ide) {
111         //ide.printStackTrace();
112         connection.getServer().doException(this, ide);
113         connection.disconnect();
114       }
115 
116       if (!connection.isConnected()) {
117         stop();
118       }
119     }
120      catch (IndyException ex) {
121       connection.getServer().doException(this, ex);
122     }
123   }
124 }
This page was automatically generated by Maven